/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.fatec.ads.facade;

import br.edu.fatec.ads.bo.BusinessObjectAutor;
import br.edu.fatec.ads.classes.Autor;
import br.edu.fatec.ads.classes.Livro;
import br.edu.fatec.ads.util.ComboBoxItem;
import java.util.Collections;
import java.util.List;
import org.hibernate.HibernateException;

/**
 *
 * @author Ubirajara
 */
public class FacadeAutor {

    private static FacadeAutor singleton = null;
    private BusinessObjectAutor regraNegocio = null;

    private FacadeAutor() {
        regraNegocio = new BusinessObjectAutor();
    }

    public static FacadeAutor getInstance()
    {
        if(singleton == null){
            singleton = new FacadeAutor();
        }

        return singleton;
    }

    public List<ComboBoxItem> recuperarTodosAutores(){
        List<ComboBoxItem> comboItems = Collections.EMPTY_LIST;
        
        regraNegocio.beginTransaction();

        try{
            List<Autor> autores = regraNegocio.recuperarTodosAutores();
            comboItems = regraNegocio.recuperarComboAutores(autores);

            regraNegocio.commitTransaction();
        }catch(HibernateException cause){
            cause.printStackTrace();
            regraNegocio.rollbackTransaction();
        }
        
        return comboItems;
    }

}
